﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;


// Extra info:
//
// Login string which will work but returns error, might have to do something with cookie?
// https://login.wartburg.nl/nidp/idff/sso?id=8&sid=0&option=credential&sid=0&Ecom_User_ID=515051&sid=0&Ecom_Password=fh9e1n&sid=0
//



namespace WartburgInfo
{
    public partial class loginInfo : Form
    {
        public loginInfo()
        {
            InitializeComponent();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            if (rememberCheck.Checked)
            {
                using (StreamWriter save = new StreamWriter(Application.StartupPath + @"\inloginfo.dat"))
                {
                    save.WriteLine(txtUsername.Text);
                    save.WriteLine(txtPassword.Text);
                }
            }
            Login();
        }

        private void txtPassword_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                Login();
            }
        }

        private void Login()
        {
            if (txtUsername.TextLength > 0 & txtPassword.TextLength > 0)
            {
                inlogInfo.username = txtUsername.Text;
                inlogInfo.password = txtPassword.Text;
                Close();
            }
            else
            {
                MessageBox.Show("Vul je gebruikersnaam en wachtwoord in!");
            }
        }

        private void loginInfo_Load(object sender, EventArgs e)
        {
            if (File.Exists(Application.StartupPath + @"\inloginfo.dat"))
            {
                using (StreamReader openLogindata = new StreamReader(Application.StartupPath + @"\inloginfo.dat"))
                {
                    txtUsername.Text = openLogindata.ReadLine();
                    txtPassword.Text = openLogindata.ReadLine();
                    rememberCheck.Checked = true;
                }
            }
        }
    }
}
